{extend name="layout/plugin_layout" /}
﻿
{block name="title"}{$plugin.title} - {$app.title}{/block}
{block name="head"}
<script src="https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js"></script>
{/block}
{block name="main"}
<div class="container mx-auto" id="app">
    <div class="card lg:card-side bordered shadow-lg">
        <div class="card-body overflow-auto">
            <div class="main">

                <div class="form-control">
                    <label class="label">
                        <span class="label-text">字符串</span>
                    </label>
                    <textarea v-model="set.input" class="textarea textarea-bordered  h-64"></textarea>
                </div>
                <div class="card-actions mt-4">
                    <button class="btn btn-primary flex-1" @click="encode">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
                             stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M17 13l-5 5m0 0l-5-5m5 5V6"/>
                        </svg>
                        编码
                    </button>
                    <button class="btn btn-primary flex-1" @click="decode">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
                             stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M7 11l5-5m0 0l5 5m-5-5v12"/>
                        </svg>
                        解码
                    </button>
                    <button class="btn btn-primary flex-1" @click="reset">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd"
                                  d="M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z"
                                  clip-rule="evenodd"/>
                        </svg>
                        清空
                    </button>
                </div>
                <div class="form-control">
                    <label class="label">
                        <span class="label-text">结果</span>
                    </label>
                    <textarea v-model="set.output" class="textarea textarea-bordered  h-64"></textarea>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            set: {
                input: '',
                output: '',
            },
        },
        created() {
        },
        methods: {
            encode() {
                try {
                    const wordArray = CryptoJS.enc.Utf8.parse(this.set.input);
                    this.set.output = CryptoJS.enc.Base64.stringify(wordArray);
                } catch (e) {
                    $message.error(e.message)
                }
            },
            decode() {
                try {
                    this.set.input = CryptoJS.enc.Base64.parse(this.set.output).toString(CryptoJS.enc.Utf8);
                } catch (e) {
                    $message.error(e.message)
                }

            },
            reset() {
                this.set.input = ''
                this.set.output = ''

            },
        },
    })

</script>

{/block}